package com.qf.weapon;


import com.qf.hero.Fightable;

import java.util.Random;

public class HeroPlus implements Fightable {

    //名称
    private String name;
    //力量
    private int power;
    //智力
    private int intelligence;
    //敏捷
    private int agile;

    private int hp;

    //武器
    private Weapon weapon;

    public HeroPlus() {
    }

    public HeroPlus(String name, int power, int intelligence, int agile,int hp) {
        this.name = name;
        this.power = power;
        this.intelligence = intelligence;
        this.agile = agile;
        this.hp = hp;
    }

    /**
     * 使用武器进行攻击
     * @return
     */
    public int weaponAttack() {
        //1. 计算武器伤害的逻辑交给武器类去实现
        int damage = weapon.caculateDamage(this);
        return damage;
    }


    /**
     * 徒手攻击
     *
     * @return
     */
    public int attack() {
        Random random = new Random();
        // min
        int min = (int) (power * 0.8);
        // max
        int max = (int) (power * 1.2);
        // [min,max] 产生一个随机数
        // [10,20]
        int result = random.nextInt((max - min) + 1) + min;
        return result;
    }


    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPower() {
        return power;
    }

    public void setPower(int power) {
        this.power = power;
    }

    public int getIntelligence() {
        return intelligence;
    }

    public void setIntelligence(int intelligence) {
        this.intelligence = intelligence;
    }

    public int getAgile() {
        return agile;
    }

    public void setAgile(int agile) {
        this.agile = agile;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    public void setWeapon(Weapon weapon) {
        this.weapon = weapon;
    }

    @Override
    public boolean isAlive() {
        return hp>0;
    }

    @Override
    public void fight(Fightable enemy) {
        int damage = 0;
        if (weapon==null){
            damage = attack();
        }else {
            damage = weaponAttack();
        }
        enemy.takeDamage(damage);
    }

    @Override
    public void takeDamage(int damage) {
        this.hp-=damage;
    }

    @Override
    public void printInfo() {
        System.out.println("name="+name+",hp="+hp);
    }
}
